package Month07.day11;

import java.util.ArrayList;

public class test4 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student student = new Student("迪丽热巴", 12);
        Student student1 = new Student("格林尼治", 23);
        Student student2 = new Student("古力娜扎", 17);
        list.add(student);
        list.add(student1);
        list.add(student2);
        ArrayList<Student> l = getList(list);
        for (int i = 0; i < l.size(); i++) {
            Student s = l.get(i);
            String s1 = s.getName();
            int a = s.getAge();
            System.out.println(s1 + a);
        }
    }

    public static ArrayList<Student> getList(ArrayList<Student> list) {
        ArrayList<Student> newList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            int age = student.getAge();
            if (age < 18) {
                newList.add(student);
            }
        }
        return newList;
    }
}
